

// ignore: must_be_immutable
import 'package:elmer_tools/common/Utils.dart';
import 'package:elmer_tools/pages/widget/button/LoginButton.dart';
import 'package:elmer_tools/pages/widget/input/LoginInput.dart';
import 'package:flutter/material.dart';

class Login extends StatelessWidget {
    bool inputDisabled = false;
    int tim = 0;

    Login({super.key});
    void onLoginTap(BuildContext context) {
        Navigator.of(context).pushNamed("/users");
    }
    @override
    Widget build(BuildContext context) {
        double width = Utils.getWidth(context), height = Utils.getHeight(context);
        double topHeight = height * 0.45;
        double headerRadius = Utils.calcWidth(120, 120, 120);
        double headerTop = topHeight - headerRadius - 100;
        double logonButtonWidth = width - 90;
        double logonButtonHeight = 50;
        return Scaffold(
            body: SingleChildScrollView(
                child: Container(
                    height: height,
                    width: width,
                    decoration: const BoxDecoration(
                        image: DecorationImage(
                            image: ExactAssetImage("assets/img-01.jpg"),
                            fit: BoxFit.fill
                        )
                    ),
                    child: Container(
                        height: height,
                        width: width,
                        decoration: const BoxDecoration(
                            gradient: LinearGradient(
                                colors: [
                                    Color.fromARGB(220, 0, 91,234),
                                    Color.fromARGB(200, 0, 198, 251)
                                ],
                                begin: Alignment.bottomCenter,
                                end: Alignment.topCenter
                            )
                        ),
                        child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                                // 用户头像或公司logo
                                SizedBox(
                                    height: topHeight,
                                    width: width,
                                    child: Padding(
                                        padding: EdgeInsets.fromLTRB(0, headerTop, 0, 20),
                                        child: Column(
                                            crossAxisAlignment: CrossAxisAlignment.center,
                                            children: <Widget>[
                                                CircleAvatar(
                                                    radius: headerRadius / 2,
                                                    backgroundImage: const AssetImage("assets/avatar-01.jpg"),
                                                ),
                                            ],
                                        ),
                                    )
                                ),
                                // 登录输入区域
                                Padding(
                                    padding: const EdgeInsets.fromLTRB(40, 0, 40, 0),
                                    child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: <Widget>[
                                            LoginInput(placeholder: "请输入邮箱或手机",icon: Icons.account_circle, disabled: inputDisabled, margin: const EdgeInsets.fromLTRB(0, 15, 0, 0),),
                                            LoginInput(placeholder: "请输入密码", icon: Icons.lock, margin: const EdgeInsets.fromLTRB(0, 25, 0, 0), isPassword: true,disabled: inputDisabled)
                                        ],
                                    )
                                ),
                                Container(
                                    padding: const EdgeInsets.fromLTRB(40, 80, 40,20),
                                    width: width,
                                    child: Column(
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: <Widget>[
                                           LoginButton(
                                                width: logonButtonWidth,
                                                height: logonButtonHeight,
                                                borderRadius: 50.0,
                                                title: "登录",
                                                onTap: () => onLoginTap(context),
                                            )
                                        ],
                                    )
                                )
                            ],
                        ),
                    )
                )
            )
        );
    }
}